From 57aaf00a0c7db0c5a98f6609afdc1dbaf41c32ef Mon Sep 17 00:00:00 2001 From: german77 Date: Wed, 15 Feb 2023 20:57:45 -0600 Subject: Qt: Fix mouse scalling --- src/yuzu/bootmanager.cpp | 24 ++++++++---------------- src/yuzu/bootmanager.h | 2 -- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 352300e88..a64e63a39 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -401,12 +401,6 @@ qreal GRenderWindow::windowPixelRatio() const { return devicePixelRatioF(); } -std::pair GRenderWindow::ScaleTouch(const QPointF& pos) const { - const qreal pixel_ratio = windowPixelRatio(); - return {static_cast(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})), - static_cast(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))}; -} - void GRenderWindow::closeEvent(QCloseEvent* event) { emit Closed(); QWidget::closeEvent(event); @@ -649,10 +643,9 @@ void GRenderWindow::mousePressEvent(QMouseEvent* event) { // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse // coordinates and map them to the current render area const auto pos = mapFromGlobal(QCursor::pos()); - const auto [x, y] = ScaleTouch(pos); - const auto [touch_x, touch_y] = MapToTouchScreen(x, y); + const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); const auto button = QtButtonToMouseButton(event->button()); - input_subsystem->GetMouse()->PressButton(x, y, touch_x, touch_y, button); + input_subsystem->GetMouse()->PressButton(pos.x(), pos.y(), touch_x, touch_y, button); emit MouseActivity(); } @@ -665,11 +658,10 @@ void GRenderWindow::mouseMoveEvent(QMouseEvent* event) { // Qt sometimes returns the parent coordinates. To avoid this we read the global mouse // coordinates and map them to the current render area const auto pos = mapFromGlobal(QCursor::pos()); - const auto [x, y] = ScaleTouch(pos); - const auto [touch_x, touch_y] = MapToTouchScreen(x, y); + const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); const int center_x = width() / 2; const int center_y = height() / 2; - input_subsystem->GetMouse()->MouseMove(x, y, touch_x, touch_y, center_x, center_y); + input_subsystem->GetMouse()->MouseMove(pos.x(), pos.y(), touch_x, touch_y, center_x, center_y); if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) { QCursor::setPos(mapToGlobal(QPoint{center_x, center_y})); @@ -697,8 +689,8 @@ void GRenderWindow::wheelEvent(QWheelEvent* event) { void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) { QList touch_points = event->touchPoints(); for (const auto& touch_point : touch_points) { - const auto [x, y] = ScaleTouch(touch_point.pos()); - const auto [touch_x, touch_y] = MapToTouchScreen(x, y); + const auto pos = touch_point.pos(); + const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); input_subsystem->GetTouchScreen()->TouchPressed(touch_x, touch_y, touch_point.id()); } } @@ -707,8 +699,8 @@ void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) { QList touch_points = event->touchPoints(); input_subsystem->GetTouchScreen()->ClearActiveFlag(); for (const auto& touch_point : touch_points) { - const auto [x, y] = ScaleTouch(touch_point.pos()); - const auto [touch_x, touch_y] = MapToTouchScreen(x, y); + const auto pos = touch_point.pos(); + const auto [touch_x, touch_y] = MapToTouchScreen(pos.x(), pos.y()); input_subsystem->GetTouchScreen()->TouchMoved(touch_x, touch_y, touch_point.id()); } input_subsystem->GetTouchScreen()->ReleaseInactiveTouch(); diff --git a/src/yuzu/bootmanager.h b/src/yuzu/bootmanager.h index 092c6206f..627e19f42 100644 --- a/src/yuzu/bootmanager.h +++ b/src/yuzu/bootmanager.h @@ -184,8 +184,6 @@ public: void CaptureScreenshot(const QString& screenshot_path); - std::pair ScaleTouch(const QPointF& pos) const; - /** * Instructs the window to re-launch the application using the specified program_index. * @param program_index Specifies the index within the application of the program to launch. -- cgit v1.2.3